package com.cs4590.finalProject.userInterface;

import android.app.Activity;
import android.content.Intent;
import android.media.AudioManager;
import android.media.SoundPool;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.TextView;

import com.cs4590.finalProject.R;

public class Piano extends Activity {
	
	String name;

	SoundPool sp;
	int explosion = 0;

	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		View v = new View(this);
		setContentView(R.layout.page_piano);
		sp = new SoundPool(3,AudioManager.STREAM_MUSIC,0);
		//explosion = sp.load(this, R.raw.hh,0);
		explosion = sp.load(Environment.getExternalStorageDirectory().getAbsolutePath() + "/default.mp3", 0);
		//explosion = sp.load("/sdcard/fish.mp3",0);


	}


	public void one(View v){
		if (explosion!=0){ 
			sp.play(explosion, 1,1,0,0,1f);
		}
	}


	public void two(View v){
		if (explosion!=0){ 
			sp.play(explosion, 1,1,0,0,1.0595f);
		}
	}


	public void three(View v){
		if (explosion!=0){ 
			sp.play(explosion, 1,1,0,0,1.1225f);
		}
	}


	public void four(View v){
		if (explosion!=0){ 
			sp.play(explosion, 1,1,0,0,1.1892f);
		}
	}


	public void five(View v){
		if (explosion!=0){ 
			sp.play(explosion, 1,1,0,0,1.2599f);
		}
	}


	public void six(View v){
		if (explosion!=0){ 
			sp.play(explosion, 1,1,0,0,1.3348f);
		}
	}


	public void seven(View v){
		if (explosion!=0){ 
			sp.play(explosion, 1,1,0,0,1.4142f);
		}
	}


	public void eight(View v){
		if (explosion!=0){ 
			sp.play(explosion, 1,1,0,0,1.4983f);
		}
	}


	public void nine(View v){
		if (explosion!=0){ 
			sp.play(explosion, 1,1,0,0,1.5874f);
		}
	}


	public void ten(View v){
		if (explosion!=0){ 
			sp.play(explosion, 1,1,0,0,1.6818f);
		}
	}


	public void eleven(View v){
		if (explosion!=0){ 
			sp.play(explosion, 1,1,0,0,1.7818f);
		}
	}


	public void twelve(View v){
		if (explosion!=0){ 
			sp.play(explosion, 1,1,0,0,1.8877f);
		}
	}


	public void thirteen(View v){
		if (explosion!=0){ 
			sp.play(explosion, 1,1,0,0,2f);
		}
	}
	
	public void changeSound(View v) {
		Intent intent = new Intent(this, SoundsDialog.class);
		startActivityForResult(intent, 1);
	}
	
	public void onActivityResult(int requestCode, int resultCode, Intent data) {
		super.onActivityResult(requestCode, resultCode, data);
		switch(requestCode) {
			case (1) : {
				if (resultCode == Activity.RESULT_OK) {
					name = data.getStringExtra("name");
					explosion = sp.load(Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + name + ".mp3", 0);
					TextView text = (TextView) findViewById(R.id.textView_piano_name);
					text.setText(name+".mp3");
				}
				break;
			}
		}
	}

}
